<?php
#region CODE
use Gotcha\App\Extensions\GotchaRoutingExtension;
use Gotcha\App\Framework\Controller;
use Modules\JasminumHotelReservations\Controllers\DefaultController;

$framework = new Controller();
$controller = new DefaultController();
$currentUrl = new GotchaRoutingExtension();
#endregion
?>
    <header>
        <h2 style="margin: 10px 0;">Zarezerwuj pokój</h2>
    </header>
    <div id="notification">
        <?php if(isset($_GET['error']) && $_GET['error'] == 1): ?>
            <div class="error">Musisz wypełnić wszystkie pola!</div>
        <?php endif; ?>
        <?php if(isset($_GET['error']) && $_GET['error'] == 2): ?>
            <div class="error">niepoprawny typ pokoju!</div>
        <?php endif; ?>
        <?php if(isset($_GET['error']) && $_GET['error'] == 3): ?>
            <div class="error">Musisz podać poprawny adres email!</div>
        <?php endif; ?>
    </div>
    <section id="jasminum-hotel-reservations">
        <form method="post" action="<?= $framework->UrlContent('/JasminumHotelReservations/Send') ?>">
            <fieldset>
                <label for="RoomColor" style="display: none;">Kolor pokoju</label>
                <select name="RoomColor" id="RoomColor" style="display: none;">
                    <option value="-1" selected="selected">--- Wybierz opcję ---</option>
                    <?php foreach($controller->getRoomColors() as $roomColorName => $roomColor): ?>
                    <option value="<?php echo $roomColor; ?>"><?php echo $roomColorName; ?></option>
                    <?php endforeach; ?>
                </select>
                <div id="RoomTypes">
                    <label for="RoomType">Typ pokoju</label>
                    <select name="RoomType" id="RoomType">
                        <option value="-1" selected="selected">--- Wybierz opcję ---</option>
                        <?php foreach($controller->getRoomTypes() as $roomTypeName => $roomType): ?>
                            <option value="<?php echo $roomType; ?>"><?php echo $roomTypeName; ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div id="ReservationInfo">
                    <label for="Firstname">Imie</label>
                    <input type="text" name="Firstname" id="Firstname">
                    <label for="Lastname">Nazwisko</label>
                    <input type="text" name="Lastname" id="Lastname">
                    <label for="Phone">Telefon</label>
                    <input type="text" name="Phone" id="Phone">
                    <label for="Email">Adres e-mail</label>
                    <input type="text" name="Email" id="Email">
                    <label for="DateFrom">Data od</label>
                    <input type="text" name="DateFrom" id="DateFrom" placeholder="RRRR-MM-DD" style="width: 93px;" maxlength="10">
                    <div class="clearfix"></div>
                    <label for="DateTo">Data do</label>
                    <input type="text" name="DateTo" id="DateTo" placeholder="RRRR-MM-DD" style="width: 93px;" maxlength="10">
                    <div class="clearfix"></div>
                    <button>Wyślij</button>
                    <input type="hidden" name="ReturnURL" value="<?= $currentUrl; ?>">
                </div>
            </fieldset>
        </form>
    </section>
    <script>
    var optionsType = $("#RoomType").html();

    // Reset options
    $('#RoomColor').find('options').each(function() {
        if($(this).val() == '-1') {
            $(this).attr('selected', 'selected');
        }
    });

    /*$('#RoomColor').change(function() {
       switch ($(this).val()) {
           case '-1':
               $('#RoomTypes').fadeOut();
               $('#ReservationInfo').fadeOut();
               break;
           case '0':
               $('#RoomType').html(optionsType);
               // Hide invalid options
               $('#RoomType').find('option').each(function() {
                   // Reset visibility
                   $(this).show();

                   // Hide
                    if($(this).val() == '2') {
                        $(this).remove();
                    }
               });
               $('#RoomTypes').fadeIn();
               break;
           case '1':
               $('#RoomType').html(optionsType);
               // Hide invalid options
               $('#RoomType').find('option').each(function() {
                   // Reset visibility
                   $(this).show();

                   // Hide
                   if($(this).val() == '1') {
                       $(this).remove();
                   }
               });
               $('#RoomTypes').fadeIn();
               break;
           case '2':
               $('#RoomType').html(optionsType);
               // Hide invalid options
               $('#RoomType').find('option').each(function() {
                   // Reset visibility
                   $(this).show();

                   // Hide
                   if($(this).val() == '1' || $(this).val() == '2') {
                       $(this).remove();
                   }
               });
               $('#RoomTypes').fadeIn();
               break;
       }
    });*/

    $('#RoomType').change(function() {
        if($(this).val() != '-1') {
            $('#ReservationInfo').fadeIn();
        } else {
            $('#ReservationInfo').fadeOut();
        }
    });
    </script>